package org.jeecg.modules.wlhy.report;


import org.jeecg.common.constant.enums.ReportPlatformEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.utils.HyCfgUtil;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class ReportServiceFactory {

    private static ConcurrentHashMap<ReportPlatformEnum, IReportService> _service= new ConcurrentHashMap <>();

    public ReportServiceFactory(@Autowired List<IReportService> reportServices) {
        for (IReportService service : reportServices) {
            ReportPlatformEnum reportType = service.getReportType();
            if(_service.containsKey(reportType)){
                throw new JeecgBootException("上报类型重复");
            }
            _service.put(reportType, service);
        }
    }

    public static IReportService getReportService(ReportPlatformEnum reportType){
        IReportService service = _service.get(reportType);
        return service;
    }

    /**
     * 检查相关的上报是否开启，参数是否配置等操作
     * @param
     */
    public static void checkReport(){
    }

    public static IReportService getReport(int  code){
        ReportPlatformEnum reportType = ReportPlatformEnum.getReportPlatformEnumByVal(code);
        if(reportType == null){
            throw new JeecgBootException("上报类型错误");
        }
        return getReportService(reportType);
    }

}
